<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

	class Dashboard extends Admin_Controller{
		public function __construct(){
			parent::__construct();
			$this->load->model('database_model');
		}

		public function index(){
			if(!is_user_logged_in())
				redirect('admin/login','refresh');
			// alert
			$alert = array(
				'alert_type' => 'info',
				'alert_content' => "Welcome to Dashboard!"
				);

			// Dashboard items
			$badge_item_posts = $this->database_model->Count('ci_posts', array('post_type' => 'post'));
			$item_posts_content = $this->database_model->GetWhere('ci_posts', array('post_type' => 'post'), 5)->result();
			$data_item_posts = array(
				'title' => 'All Posts',
				'badge' => $badge_item_posts,
				'content' => $item_posts_content
				);
			$item_posts = getView('modules/dashboard-item', $data_item_posts, true);

			$badge_item_pages = $this->database_model->Count('ci_posts', array('post_type' => 'page'));
			$data_item_pages = array(
				'title' => 'All Pages',
				'badge' => $badge_item_pages,
				'content' => 'Content'
				);
			$item_pages = getView('modules/dashboard-item', $data_item_pages, true);

			$dashboard_content = array(
				'item_posts' => $item_posts,
				'item_pages' => $item_pages,
				);

			// Load dashboard
			$data = array(
				'header' => 'Dashboard',
				'menu_active' =>"1",
				'alert' => $alert,
				'dashboard_content' => $dashboard_content
				);
			$this->load->view('admin/dashboard', $data);
		}
	}
?>